package com.vincent.kdp.ui.fragment.presenter;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.Toast;

import com.vincent.baseapp.base.BasePresenter;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.bean.entity.VipInfo;
import com.vincent.kdp.ui.bean.response.VipInfoOutput;
import com.vincent.kdp.ui.fragment.contract.VipContract;
import com.vincent.kdp.ui.fragment.repository.VipRepository;
import com.vincent.kdp.ui.vip.VipDetailActivity;

public class VipPresenter extends BasePresenter<VipContract.View> implements VipContract.Presenter {
    private VipRepository mRepository;

    public VipPresenter() {
        mRepository = new VipRepository();
    }

    @Override
    public void initView(Intent intent) {

    }

    @Override
    public void reqVipInfo(String number) {
        if (mView.getVipAccount().trim().equals("")) {
            mView.showToast("请输入会员卡号或手机号码");
            return;
        }
        if (mView.getVipAccount().trim().length()!=11) {
            mView.showToast("请输入11位的会员卡号或手机号码");
            return;
        }
        mView.showLoadDialog();
        mRepository.reqVipInfo(mView.getVipAccount().trim(), number,new RequestCallBack<VipInfoOutput>() {
            @Override
            public void onSuccess(VipInfoOutput object) {
                if (mView != null) {
                    mView.dismissLoadDialog();
                    if (object.getData() != null){
                        VipInfo vipInfo=object.getData();
                        vipInfo.setPhoneOrCard(mView.getVipAccount().trim());
                        mView.gotoNext(vipInfo);
                    }

                    if (TextUtils.isEmpty(object.getMsg())) {
                        mView.showToast("系统异常");
                    } else {
                       // mView.showToast(object.getMsg());
                    }
                    mView.setVipAccount();
                }
            }

            @Override
            public void onFalse(String msg) {
                if (mView != null) {
                    mView.dismissLoadDialog();
                    mView.showToast(msg);
                }
            }
        });
    }
}
